package vk
{
  import asunit.framework.TestCase;

  /**
   * ...
   * @author Roman Marchenko
   */
  public class TestVK extends TestCase
  {

    public function TestVK(testMethod:String = null)
    {
      super(testMethod);
    }

    override protected function setUp():void
    {
      Api.setUp(new Object); // empty vars array
    }

    public function testGetCountries():void
    {
      var onOk:Function = function(countries:Object):void
      {
        assertNotNull(countries);
        assertTrue(0 < countries.length);
        for (var i:int = 0; i < countries.length; ++i)
        {
          switch (countries[i].cid)
          {
            case 0:
            {
              assertTrue(false); // should never be
              break;
            }
            case 1:
            {
              assertEquals(countries[i].title, "Россия");
              break;
            }
            case 2:
            {
              assertEquals(countries[i].title, "Украина");
              break;
            }
            case 3:
            {
              assertEquals(countries[i].title, "Беларусь");
              break;
            }
          }
          assertEquals(countries.length, 100);
        }
      }

      var onError:Function = function(obj:Object):void
      {
        assertTrue(false); // should never be
      }

      var VK:Api = new Api;
      VK.api("places.getCountries", {"need_full": 1}, addAsync(onOk, 10000), onError);
    }

    public function testGetProfiles():void
    {
      var onOk:Function = function(profile:Object):void
      {
        assertNotNull(profile);
        assertEquals(profile.length, 1);
        assertEquals(profile[0].uid, LocalTesting.VIEWER_ID);
        assertEquals(profile[0].country, 1);
      }

      var onError:Function = function(obj:Object):void
      {
        assertTrue(false); // should never be
      }

      var VK:Api = new Api;
      VK.api("getProfiles", {"uids": LocalTesting.VIEWER_ID, "fields": "first_name,last_name,nickname,screen_name,sex,country"}, addAsync(onOk, 10000), onError);
    }
  }
}